
var formatter = function (value, row, index) {
    if(role==1){
        return ['<a href="javascript:void(0)" class="detail">查看</a>'
        + '&nbsp;&nbsp;<a href="javascript:void(0)" class="deletepro">删除</a>'
        + '&nbsp;&nbsp;<a href="javascript:void(0)" class="alterpro">修改</a>'].join('');
    }else{
        return ['<a href="javascript:void(0)" class="detail">查看</a>'
        + '&nbsp;&nbsp;<a href="javascript:void(0)" class="deletepro">删除</a>'].join('');
    }
}




$("#closeBtn").click(function () {
    closeModel("finddetail-div");
});


bindClick("#okBtn", function () {
    var reason = $.trim($("#auditreason").val());
    var id = $("#id").val();
    var mobile = $("#mobile").val();
    var email = $("#proposerEmail").val();
    var proposer = $("#proposer").val();
    var projectName = $("#projectName").val();


    comment.showOperationTips("确认审核通过申报项目并发送邮件与短信吗？", function () {
        $.post($().AbsUrlParse('/web/userproject/auditproject'), {
            id: id,
            mobile: mobile,
            state: '审核通过',
            email:email,
            reason: reason,
            proposer:proposer,
            projectName:projectName
        }, function (data) {
            if (data.state == true) {
                if (data.res.code == 40000) {
                    closeModel("finddetail-div");
                    hint("申报项目已审核成功并发送了邮件与短信");
                    var table = $('#table');
                    table.bootstrapTable('refresh');
                } else {
                    hint(data.res.msg);
                }
            } else {
                hint(data.msg);
            }
        });
    });
    return false;
});

bindClick("#noBtn", function () {
    var reason = $.trim($("#auditreason").val());
    var id = $("#id").val();
    var mobile = $("#mobile").val();
    var email = $("#proposerEmail").val();
    var proposer = $("#proposer").val();


    if ("" == reason) {
        hint("请填写审核失败原因");
        return false;
    }


    comment.showOperationTips("确认审核不通过申报项目吗？", function () {
        $.post($().AbsUrlParse('/web/userproject/auditproject'), {
            id: id,
            mobile: mobile,
            state: '审核失败',
            email:email,
            reason: reason,
            proposer:proposer
        }, function (data) {
            if (data.state == true) {
                if (data.res.code == 40000) {
                    closeModel("finddetail-div");
                    hint("申报项目已更改为审核失败并发送了邮件及短信");
                    var table = $('#table');
                    table.bootstrapTable('refresh');
                } else {
                    hint(data.res.msg);
                }
            } else {
                hint(data.msg);
            }
        });
    });
    return false;
});

//修改的代码
bindClick("#btnsearch", function () {

    console.log('1');

    //下面是每次查询
    var hangye = $("select[name=hangye]").val();
    var state = $("select[name=state]").val();
    var ipt_regtime = $("input[name=ipt_regtime]").val();
    var ipt_created = $("input[name=ipt_created]").val();
    var search = $("input[name=shengqingren]").val();

    //如果是组委的时候才会有这个
    var parkId = $("select[name=park_name]").val();



    //如果不是级委会的话，查询的时候每交都会带这两个参数过去
    var default_user_role = $("input[name=default_user_role]").val();
    var default_park_name = $("input[name=default_park_name]").val();


    var parkName ="";
    $("#yuanqu option:checked").each(function(){
        parkName = $(this).html();
        if(parkName=="选择所属园区"){
            parkName="";
        }
    })

    var cstart = "";
    var cend = "";
    var start = "";
    var end = "";

    if (ipt_created != null) {
        cstart = ipt_created.split(" - ")[0];
        cend = ipt_created.split(" - ")[1];
    }

    if (ipt_regtime != null) {
        start = ipt_regtime.split(" - ")[0];
        end = ipt_regtime.split(" - ")[1];
    }

    var url = $().AbsUrlParse("/web/userproject/finalList?search=" + search
        + "&hangye=" + hangye + "&state=" + state + "&entrestartdate="
        + start + "&entreenddate=" + end + "&cstart=" + cstart + "&cend=" + cend + "&parkId=" + parkId + "" +
        "&default_user_role=" + default_user_role + "&default_park_name=" + default_park_name+
        "&parkName=" + parkName);

    $("#table").bootstrapTable("refresh", {"url": url});


});

bindClick("#btnexport", function () {

    var hangye = $("select[name=hangye]").val();
    var state = $("select[name=state]").val();
    var parkId = $("#yuanqu").val();
    var ipt_regtime = $("input[name=ipt_regtime]").val();
    var ipt_created = $("input[name=ipt_created]").val();
    var search = $("input[name=shengqingren]").val();



    var start = "", end = "";
    var cstart = "", cend = "";

    if (ipt_created != null) {
        cstart = ipt_created.split(" - ")[0];
        cend = ipt_created.split(" - ")[1];
    }

    if (ipt_regtime != null) {
        start = ipt_regtime.split(" - ")[0];
        end = ipt_regtime.split(" - ")[1];
    }


    $.post($().AbsUrlParse("/web/userproject/finalListExport"), {
        search: search,
        hangye: hangye,
        parkId: parkId,
        state: state,
        entrestartdate: start,
        entreenddate: end,
        cstart: cstart,
        cend: cend
    }, function (data) {
        if (data.state == true) {
            if (data.res.code == 40000) {
                var a = document.createElement("a");
                a.href = $().AbsUrlParse("/excel/" + data.res.data);
                a.click();
            } else {
                hint(data.res.msg);
            }
        } else {
            hint(data.msg);
        }
    });
});


var auditFormatter = function (value, row, index) {
    if (value == '等待审核') {
        return ['<span style="color: blue">' + value + '</span>'].join('');
    } else if (value == '审核通过') {
        return ['<span style="color: lightgreen">' + value + '</span>'].join('');
    } else if (value == '审核失败') {
        return ['<span style="color:red">' + value + '</span>'].join('');
    }

}


function initDateRange() {
    $(".rangedate").daterangepicker({
        "autoApply": true,
        "locale": {
            "applyLabel": "确定",
            "cancelLabel": "取消",
            "fromLabel": "开始",
            "toLabel": "结束",
            "customRangeLabel": "Custom",
            "weekLabel": "周",
            "daysOfWeek": [
                "日",
                "一",
                "二",
                "三",
                "四",
                "五",
                "六"
            ],
            "monthNames": [
                "1月",
                "2月",
                "3月",
                "4月",
                "5月",
                "6月",
                "7月",
                "8月",
                "9月",
                "10月",
                "11月",
                "12月"
            ],
            "cancelLabel": '清空',
            "opens": "right"
        },
        "format": "YYYY-MM-DD"
    }).on('cancel.daterangepicker', function (ev, picker) {
        $(this).val('');
    });
}

bindClick("#clickVideo", function () {
    var filePath = $("input[name=videoPath]").val();
    if ("" != filePath) {
        var a = document.createElement("a");
        a.href = filePath;
        a.target = "_blank";
        a.click();
    } else {
        hint("未上传宣传视频")
    }
    return false;
});


//点击查看项目详情
var clickDetail = function (row) {

    showModel("finddetail-div", function () {
        // if (row.auditState == '等待审核') {
        //     $("#okBtn").show();
        //     $("#noBtn").show();
        // }
        setRowToFrm("detailProForm", row);

        if("是"==row.isRegEnterprice){
            $(".isHidd").show();
        }

        //如果审核原因是暂无的话，就不显示出来
        if(row.auditReason=='暂无'){
            var auditreason = document.getElementById("auditreason");
            auditreason.value='';
        }


        if (row.videoPath != null && row.videoPath != '') {
            $("#clickVideo").show();
        } else {
            $("#clickVideo").hide();
        }

        $("#downloadDiv").html("");

        if (row.attachmentPath != null) {
            if (row.attachmentPath.indexOf(",") != -1) {
                var pathArray = row.attachmentPath.split(",");
                var btnButton = "";
                for (var i = 0; i < pathArray.length; i++) {
                    var filenameArray = pathArray[i].split('\/');
                    var filename = filenameArray[filenameArray.length - 1];
                    btnButton = btnButton + "<button class='fileBtn' data-value='" + pathArray[i] + "'>" + (i + 1) + '. ' + filename + " - 点击下载</button><br/><br/>";
                }
                $("#downloadDiv").html(btnButton);
            } else {
                var filenameArray = row.attachmentPath.split('\/');
                var filename = filenameArray[filenameArray.length - 1];
                $("#downloadDiv").html("<button class='fileBtn' data-value='" + row.attachmentPath + "'>" + filename + " - 点击下载</button>");
            }

            $("#downloadDiv").find(".fileBtn").click(function () {
                var filePath = $(this).data("value");
                if ("" != filePath) {
                    var a = document.createElement("a");
                    a.href = File_Download_Url + filePath;
                    var filePathArray = filePath.split('\/');
                    var filename = filePathArray[filePathArray.length - 1];
                    a.download = filename;
                    a.target = "_blank";
                    a.click();
                } else {
                    hint("未上传商业计划书");
                }
                return false;
            });
        }

    });
}

window.operateEvents = {
    'click .detail': function (e, value, row, index) {
        clickDetail(row);
    },
    'click .deletepro': function (e, value, row, index) {
        comment.showOperationTips("确定删除项目吗？", function () {
            $.post($().AbsUrlParse('/web/userproject/deleteproject'), {
                id: row.id
            }, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("删除成功");
                        var table = $('#table');
                        table.bootstrapTable('refresh');
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        });
    },
    'click .alterpro':function(e,value,row,index){
        showModel("finddetail-div-alter",function(){
            setRowToFrm("detailProFormAlter",row)
        });
    }
};




//初始化页面的时候运行该函数
$(function () {
    initDateRange();
});


//下面是修改的确认按钮
bindClick("#okAlter",function(){
//下面是修改的确认按钮
    var form = $("#detailProFormAlter");


    //下面是进行验证
    var isregist = $("#isRegEnterpriceAlter").val();
    if(isregist=='是'){
        var inputs = form.find("input");
        var textareas = form.find("textarea")

        for(var i=0;i<inputs.length;i++){
            if(inputs[i].value==''){
                hint("不能有空项")
                return false;
            }
        }
        for(var i=0;i<textareas.length;i++){
            if(textareas[i].value==''){
                hint("不能有空项")
                return false;
            }
        }
    }else{
        var inputs = form.find("input:not(.noreg)");
        var textareas = form.find("textarea")
        for(var i=0;i<inputs.length;i++){
            if(inputs[i].value==''){
                hint("除企业注册时间和企业注册地外都应填写")
                return false;
            }
        }
        for(var i=0;i<textareas.length;i++){
            if(textareas[i].value==''){
                hint("除企业注册时间和企业注册地外都应填写")
                return false;
            }
        }
    }


    var params = form.formToArray();
    comment.post(form.attr("action"), params, '执行保存', function (res) {
        if (res.res.code == 40000) {
            //关闭model方法
            closeModel("finddetail-div-alter");
            var table = $("#table");
            table.bootstrapTable("refresh");
        }else{
            hint(res.res.msg);
        }
    });
});



//下面是对分数的格式化
var sumScoreFormatter = function(value,row,index){
    if(value==null){
        return 0;
    }else{
        return value;
    }
}

